package com.gxa.j259.springcloud.f.ribbon.controller;

import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;

/**
 * @author thinknovo
 * @version 1.0
 */
@RestController
public class RestTemplateController {

    @Resource
    private RestTemplate restTemplate;

    @RequestMapping(value = "/check",method = RequestMethod.GET,
            produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map check(String name) {
        // 这里调用的是client模块EurekaclientApplication中的check请求路径
        // 需要注意的是EUREKA-CLIENT是server中加载的客户端名字，默认全部大写
        Map map = restTemplate.getForObject("http://EUREKA-CLIENT-8861/check?name=" + name, Map.class);
        return map;
    }
}
